package shuashuami.hb.com.http;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * <b>类   名：</b>${TYPE_NAME} <br/>
 * <b>类描述：</b> <br/>
 * <b>创建人：</b>zhangqi<br/>
 * <b>创建时间：</b>2017/6/28<br/>
 * <b>修改人：</b>zhangqi<br/>
 * <b>修改时间：</b>2017/6/28<br/>
 * <b>修改备注：</b><br/>
 *
 * @version 1.0.0<br/>
 */
public class HttpBMethods {


    //获取任务列表
    public static void getBuserInfo(final HttpOnNextListener listener, String shopId) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", shopId + "");

        HttpUtils.doPost(BURLs.userInfo, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void addTask(final HttpOnNextListener listener, String shopId, String task_id) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", shopId + "");
        map.put("task_id", task_id);

        HttpUtils.doPost(BURLs.addTask, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //编辑用户信息
    public static void userEdit(final HttpOnNextListener listener, String brsuhId, String type, String data) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);
        map.put("type", type);
        map.put("data", data);


        HttpUtils.doPost(BURLs.userEdit, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void distributionCenter(final HttpOnNextListener listener, String type, String brushId, String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("type", type);
        map.put("shopId", brushId);
        map.put("page", page);
        map.put("size", size);

        HttpUtils.doPost(BURLs.distributionCenter, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getDaishenheTask(final HttpOnNextListener listener, String brachid,
                                        String status, String page,
                                        String size,String keyword) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brachid + "");
        map.put("status", status);
        map.put("page", page);
        map.put("size", size);
        map.put("keyword",keyword);



        HttpUtils.doPost(BURLs.taskList, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //我的刷手
    public static void recommendListc(final HttpOnNextListener listener, String brushId, String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brushId);
        map.put("page", page);
        map.put("size", size);

        HttpUtils.doPost(BURLs.recommendList, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getYuE(final HttpOnNextListener listener, String brsuhId) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);

        HttpUtils.doPost(BURLs.getYuE, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getZhifubao(final HttpOnNextListener listener, String brsuhId) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);

        HttpUtils.doPost(BURLs.getZhifubao, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getBank(final HttpOnNextListener listener, String brsuhId) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);

        HttpUtils.doPost(BURLs.getYInhangkaInfo, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void saveZhifubao(final HttpOnNextListener listener, String brsuhId, String name, String num) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);
        map.put("alipay_realname", name);
        map.put("alipay_account", num);

        HttpUtils.doPost(BURLs.saveZhifubao, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void saveYinhangka(final HttpOnNextListener listener, String brsuhId, String bankcard_name, String bankcard_identify
            , String bankcard_no, String bank_id, String bankcard_address, String bankcard_info) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);
        map.put("bankcard_name", bankcard_name);
        map.put("bankcard_identify", bankcard_identify);
        map.put("bankcard_no", bankcard_no);
        map.put("bank_id", bank_id);
        map.put("bankcard_address", bankcard_address);
        map.put("bankcard_info", bankcard_info);

        HttpUtils.doPost(BURLs.saveYInhangka, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getJilu(final HttpOnNextListener listener, String brsuhId, String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);
        map.put("page", page);
        map.put("size", size);

        HttpUtils.doPost(BURLs.jilu, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void tixian(final HttpOnNextListener listener, String brsuhId, String money, String type) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);
        map.put("money", money);
        map.put("type", type);

        HttpUtils.doPost(BURLs.tixian, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getYongJinmingxi(final HttpOnNextListener listener, String brsuhId, String page, String type, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);
        map.put("page", page);
        map.put("type", type);
        map.put("size", size);

        HttpUtils.doPost(BURLs.yongjinmingxi, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getWeitongguo(final HttpOnNextListener listener, String brsuhId, String task_id) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);
        map.put("task_id", task_id);

        HttpUtils.doPost(BURLs.weishenheInfo, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void submitTask(final HttpOnNextListener listener, String brsuhId, String task_id) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);
        map.put("apply_id", task_id);

        HttpUtils.doPost(BURLs.querendingdan, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void bohui(final HttpOnNextListener listener, String brsuhId, String task_id, String content) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);
        map.put("apply_id", task_id);
        map.put("content", content);

        HttpUtils.doPost(BURLs.bohui, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getFenxiaoyongjin(final HttpOnNextListener listener, String brsuhId) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);

        HttpUtils.doPost(BURLs.distributionMoney, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getComplaintList(final HttpOnNextListener listener, String brachid, String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brachid + "");
        map.put("page", page);
        map.put("size", size);


        HttpUtils.doPost(BURLs.complainList, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getWodeFabu(final HttpOnNextListener listener,
                                   String brachid, String keyword,
                                   String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brachid + "");
        map.put("keyword", keyword);
        map.put("page", page);
        map.put("size", size);


        HttpUtils.doPost(BURLs.wodefabu, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void baseConfig(final HttpOnNextListener listener) {

        HttpUtils.doGet(BURLs.baseConfig, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }
    //修改密码
    public static void changePassword(final HttpOnNextListener listener, String brsuhId, String oldpwd, String pwd, String repwd) {
        Map<String, String> map = new HashMap<>();
        map.put("shopId", brsuhId);
        map.put("oldpwd", oldpwd);
        map.put("pwd", pwd);
        map.put("repwd", repwd);

        HttpUtils.doPost(BURLs.changePassword, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }
}
